package TransactionImplementation

import (
	"SalaryPayment/DataBase"
	"SalaryPayment/ModelImplementation"
	"fmt"
	"log"
	"reflect"
	"strconv"
	"time"
)

type TimeCardTransaction struct {
	itsDate  time.Time
	itsHours float64
	itsEmpId int
}

func (tct *TimeCardTransaction) Execute() {
	e := DataBase.PayrollDatabase.GetUnionMember(tct.itsEmpId)

	if e != nil {
		pc := e.GetClassification()

		if reflect.TypeOf(pc) == reflect.TypeOf(ModelImplementation.HourlyClassification{}) {
			hr := pc.(*ModelImplementation.HourlyClassification)
			sr := ModelImplementation.NewTimeCard(tct.itsDate, tct.itsHours)
			hr.AddTimeCard(sr)
		} else {
			log.Println(fmt.Errorf(DataBase.PayrollExceptionMessage.NotHourlyClassification +
				strconv.Itoa(e.GetEmpid())))
		}
	} else {
		log.Println(fmt.Errorf(DataBase.PayrollExceptionMessage.EmployeeNotExist + strconv.Itoa(e.GetEmpid())))
	}
}
